Slide 24

The Building Block: A `Node` Class

Every tree is built from a collection of these simple objects.

Python Code

# A Node represents one position in the tree.
# It holds a value and has two pointers,
# which can point to other nodes or be None.

class Node:
    def __init__(self, val, left=None, right=None):
        # The value stored at this node (e.g., '5' or '+')
        self.val = val
        
        # A pointer to the left child node
        self.left = left
        
        # A pointer to the right child node
        self.right = right

Conceptual View

val
left child
right child